#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_btnInitItems_clicked()
{
    QIcon icon;
    icon.addFile(":image/icons/aim.icon");
    ui->comboBox->clear();
    for(int i=0;i<5;i++)
    {
        // ui->comboBox->addItem((icon, QString::asprintf("Item %d",i)));
        ui->comboBox->addItem(QString::asprintf("Item %d",i));
    }

    QStringList strList;
    strList<<"武汉"<<"合肥"<<"广州";
    ui->comboBox->addItems(strList);
}


void Widget::on_btnInit2_clicked()
{
    QMap<QString, int> City_Zone;
    City_Zone.insert("成都",28);
    City_Zone.insert("上海",20);
    City_Zone.insert("北京",10);
    City_Zone.insert("天津",22);
    ui->comboBox_2->clear();
    foreach(const QString &str,City_Zone.keys())
        ui->comboBox_2->addItem(str, City_Zone.value(str));
}

void Widget::on_btnToComboBox_clicked()
{
    QTextDocument *doc = ui->plainTextEdit->document();
    int cnt = doc->blockCount();
    QIcon icon(":/image/icons/aim.ico");
    ui->comboBox->clear();
    for(int i=0;i<cnt;i++)
    {
        QTextBlock textLine = doc->findBlockByNumber(i);
        QString str = textLine.text();
        ui->comboBox->addItem(icon,str);

    }
}

void Widget::on_pushButton_2_clicked()
{
    ui->comboBox->clear();
}

void Widget::on_btnClearText_clicked()
{
    ui->plainTextEdit->clear();
}

void Widget::on_checkBox_2_stateChanged(int arg1)
{
    bool stat = ui->plainTextEdit->isReadOnly();
    if(stat)
    {
        ui->plainTextEdit->setReadOnly(false);
    }
    else
    {
        ui->plainTextEdit->setReadOnly(true);
    }
}
